package com.mob.commons;

import android.content.Context;
import android.database.Cursor;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.util.Base64;
import com.mob.commons.authorize.DeviceAuthorizer;
import com.mob.tools.MobHandlerThread;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import com.mob.tools.network.KVPair;
import com.mob.tools.network.NetworkHelper.NetworkTimeOut;
import com.mob.tools.utils.Data;
import com.mob.tools.utils.DeviceHelper;
import com.mob.tools.utils.Hashon;
import com.mob.tools.utils.R;
import com.mob.tools.utils.SQLiteHelper;
import com.mob.tools.utils.SQLiteHelper.SingleTableDB;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.zip.GZIPOutputStream;

public class g
  implements Handler.Callback
{
  private static g a;
  private Context b;
  private Handler c;
  private SQLiteHelper.SingleTableDB d;
  private Hashon e;
  private DeviceHelper f;

  private g(Context paramContext)
  {
    this.b = paramContext.getApplicationContext();
    this.e = new Hashon();
    this.f = DeviceHelper.getInstance(paramContext);
    MobHandlerThread localMobHandlerThread = new MobHandlerThread();
    localMobHandlerThread.start();
    this.c = new Handler(localMobHandlerThread.getLooper(), this);
    File localFile = new File(R.getCacheRoot(paramContext), "comm/dbs/.dh");
    if (!localFile.getParentFile().exists())
      localFile.getParentFile().mkdirs();
    this.d = SQLiteHelper.getDatabase(localFile.getAbsolutePath(), "DataHeap_1");
    this.d.addField("time", "text", true);
    this.d.addField("data", "text", true);
    this.c.sendEmptyMessage(1);
  }

  public static g a(Context paramContext)
  {
    try
    {
      if (a == null)
        a = new g(paramContext);
      g localg = a;
      return localg;
    }
    finally
    {
    }
  }

  private String a(String paramString)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream(localByteArrayOutputStream);
    localGZIPOutputStream.write(paramString.getBytes("utf-8"));
    localGZIPOutputStream.flush();
    localGZIPOutputStream.close();
    byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
    return Base64.encodeToString(Data.AES128Encode("sdk.commonca.sdk".getBytes("UTF-8"), arrayOfByte), 2);
  }

  private void a()
  {
    String str = this.f.getNetworkType();
    if ((str == null) || ("none".equals(str)))
      return;
    j.a(new File(R.getCacheRoot(this.b), "comm/locks/.dhlock"), true, new i(this));
  }

  private boolean a(ArrayList<String[]> paramArrayList)
  {
    f localf;
    ArrayList localArrayList1;
    HashMap localHashMap;
    ArrayList localArrayList2;
    try
    {
      localf = f.a(this.b);
      localArrayList1 = localf.a();
      if (localArrayList1.isEmpty())
        return false;
      localHashMap = new HashMap();
      localHashMap.put("plat", Integer.valueOf(this.f.getPlatformCode()));
      localHashMap.put("device", this.f.getDeviceKey());
      localHashMap.put("mac", this.f.getMacAddress());
      localHashMap.put("model", this.f.getModel());
      localHashMap.put("duid", DeviceAuthorizer.authorize(this.b, null));
      localHashMap.put("imei", this.f.getIMEI());
      localHashMap.put("serialno", this.f.getSerialno());
      localHashMap.put("networktype", this.f.getDetailNetworkTypeForStatic());
      localArrayList2 = new ArrayList();
      Iterator localIterator = paramArrayList.iterator();
      while (localIterator.hasNext())
      {
        String[] arrayOfString = (String[])localIterator.next();
        localArrayList2.add(this.e.fromJson(arrayOfString[1]));
      }
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
      return false;
    }
    localHashMap.put("datas", localArrayList2);
    ArrayList localArrayList3 = new ArrayList();
    localArrayList3.add(new KVPair("appkey", ((MobProduct)localArrayList1.get(0)).getProductAppkey()));
    localArrayList3.add(new KVPair("m", a(this.e.fromHashMap(localHashMap))));
    ArrayList localArrayList4 = new ArrayList();
    localArrayList4.add(new KVPair("User-Identity", localf.a(localArrayList1)));
    NetworkHelper.NetworkTimeOut localNetworkTimeOut = new NetworkHelper.NetworkTimeOut();
    localNetworkTimeOut.readTimout = 30000;
    localNetworkTimeOut.connectionTimeout = 30000;
    String str = localf.httpPost("http://c.data.mob.com/cdata", localArrayList3, null, localArrayList4, localNetworkTimeOut);
    boolean bool = "200".equals(String.valueOf(this.e.fromJson(str).get("status")));
    return bool;
  }

  private ArrayList<String[]> b()
  {
    ArrayList localArrayList = new ArrayList();
    Cursor localCursor;
    try
    {
      String[] arrayOfString1 = { "time", "data" };
      localCursor = SQLiteHelper.query(this.d, arrayOfString1, null, null, null);
      if (localCursor != null)
      {
        if (!localCursor.moveToFirst())
          break label149;
        String[] arrayOfString2 = new String[2];
        arrayOfString2[0] = localCursor.getString(0);
        arrayOfString2[1] = localCursor.getString(1);
        localArrayList.add(arrayOfString2);
        while (localCursor.moveToNext())
        {
          String[] arrayOfString3 = new String[2];
          arrayOfString3[0] = localCursor.getString(0);
          arrayOfString3[1] = localCursor.getString(1);
          localArrayList.add(arrayOfString3);
        }
      }
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return localArrayList;
    label149: localCursor.close();
    return localArrayList;
  }

  private void b(ArrayList<String[]> paramArrayList)
  {
    StringBuilder localStringBuilder;
    try
    {
      localStringBuilder = new StringBuilder();
      Iterator localIterator = paramArrayList.iterator();
      while (localIterator.hasNext())
      {
        String[] arrayOfString = (String[])localIterator.next();
        if (localStringBuilder.length() > 0)
          localStringBuilder.append(", ");
        localStringBuilder.append('\'').append(arrayOfString[0]).append('\'');
      }
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
      return;
    }
    SQLiteHelper.delete(this.d, "time in (" + localStringBuilder.toString() + ")", null);
  }

  private void b(HashMap<String, Object> paramHashMap)
  {
    j.a(new File(R.getCacheRoot(this.b), "comm/locks/.dhlock"), true, new h(this, paramHashMap));
  }

  public void a(HashMap<String, Object> paramHashMap)
  {
    try
    {
      Message localMessage = new Message();
      localMessage.what = 2;
      localMessage.obj = paramHashMap;
      this.c.sendMessage(localMessage);
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public boolean handleMessage(Message paramMessage)
  {
    switch (paramMessage.what)
    {
    default:
    case 1:
    case 2:
    }
    while (true)
    {
      return false;
      a();
      this.c.sendEmptyMessageDelayed(1, 10000L);
      continue;
      b((HashMap)paramMessage.obj);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.commons.g
 * JD-Core Version:    0.6.2
 */